import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Projet
{
	public static void main(String[] args)
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = null;

		while (true)
		{
			System.out.println("\n ================== MAIN MENU ==================");
			System.out.println("|                                               |");
			System.out.println("|          c - Create a new anthill             |");
			System.out.println("|          s - Save  an anthill state           |");
			System.out.println("|          r - Reload a saved one               |");
			System.out.println("|          q - Quit                             |");
			System.out.println("|                                               |");
			System.out.println(" ===============================================\n");
			System.out.println("Your choice : ");

			try
			{
				s = br.readLine().toLowerCase();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}

			switch (s)
			{
				case "c":
					Fourmilliere f = create();
					affiche(f);
					menuJeu(f);
					break;

				case "s":
					System.out.println("TODO ==> SAVE !!");
					break;

				case "r":
					System.out.println("TODO ==> RELOAD !!");
					break;

				case "q":
					System.out.println("Exiting...");
					System.exit(0);

				default:
					break;
			}
		}
	}

	private static void affiche(Fourmilliere f)
	{
		System.out.println(f);
	}

	private static void menuJeu(Fourmilliere f)
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = null;

		while (true)
		{
			System.out.println("\n ================== GAME MENU ==================");
			System.out.println("|                                               |");
			System.out.println("|          ENTER - New day                      |");
			System.out.println("|          n - Number of days to go             |");
			System.out.println("|          m - Main menu                        |");
			System.out.println("|          q - Quit                             |");
			System.out.println("|                                               |");
			System.out.println(" ===============================================\n");
			System.out.println("Your choice : ");
			try
			{
				s = br.readLine().toLowerCase();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}

			if (s.length() == 0)
			{
				newDay(f);
			}

			switch (s)
			{
				case "n":
					System.out.println("TODO ==> NEW DAY * X !!");
					break;

				case "m":
					main(null);
					break;

				case "q":
					System.out.println("Exiting...");
					System.exit(0);

				default:
					break;
			}
		}

	}

	private static void newDay(Fourmilliere f)
	{
		f.setAgeFourmilliere(f.getAgeFourmilliere() + 1);

	}

	private static Fourmilliere create()
	{
		System.out.println("\nNumber of queens ? :");
		int queens = reply();
		System.out.println("\nNumber of males ? :");
		int males = reply();
		System.out.println("\nNumber of workers ? :");
		int workers = reply();
		System.out.println("\nNumber of larvae ? :");
		int larvae = reply();

		Fourmilliere f = new Fourmilliere(queens, males, workers, larvae);
		return f;

	}

	private static int reply()
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = null;
		boolean b = false;

		do
		{
			try
			{
				s = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			b = isInteger(s);

		} while (b == false);

		return Integer.parseInt(s);
	}

	private static boolean isInteger(String string)
	{
		try
		{
			Integer.parseInt(string);
			return true;
		}
		catch (NumberFormatException e)
		{
			System.out.println("\nPlease enter a number !");
			return false;
		}
	}
}
